package com.springboot.test.web.app;

import com.springboot.test.common.response.Response;
import com.springboot.test.entity.GoodsTypeEntity;
import com.springboot.test.service.GoodsTypeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类接口
 */
@RestController
@RequestMapping("app/goods_type")
public class GoodsTypeController {

    @Resource
    private GoodsTypeService goodsTypeService;

    /**
     * 查询商品分类
     * @return
     */
    @GetMapping("list")
    public Response<List<GoodsTypeEntity>> list(){
        return Response.success(goodsTypeService.list());
    }

    /**
     * 添加商品分类
     * @param name
     * @return
     */
    @GetMapping("add")
    public Response<Void> add(String name,String parentCode){
        goodsTypeService.add(name,parentCode);
        return Response.success();
    }

    /**
     * 根据级别和父编号查询对应分类
     * @param level
     * @param parentCode
     * @return
     */
    @GetMapping("levelList")
    public Response<List<GoodsTypeEntity>> listByCondition(Integer level,String parentCode){
        return Response.success(goodsTypeService.listByCodesAndLevel(level,parentCode));
    }

    @GetMapping("count")
    public Response<Integer> count(){
        return Response.success(goodsTypeService.typeCount());
    }
}
